package com.xiaoba.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoba.product.mapper.PmsCategoryMapper;
import com.xiaoba.product.domain.PmsCategory;
import com.xiaoba.product.service.IPmsCategoryService;

/**
 * 商品三级分类Service业务层处理
 *
 * @author gd
 * @date 2024-05-29
 */
@Service
public class PmsCategoryServiceImpl implements IPmsCategoryService
{
    @Autowired
    private PmsCategoryMapper pmsCategoryMapper;

    /**
     * 查询商品三级分类
     *
     * @param catId 商品三级分类主键
     * @return 商品三级分类
     */
    @Override
    public PmsCategory selectPmsCategoryByCatId(Long catId)
    {
        return pmsCategoryMapper.selectPmsCategoryByCatId(catId);
    }

    /**
     * 查询商品三级分类列表
     * @return 商品三级分类
     */
    @Override
    public List<PmsCategory> selectPmsCategoryList(PmsCategory pmsCategory)
    {
        return pmsCategoryMapper.selectPmsCategoryList(pmsCategory);




//        List<PmsCategory> pmsCategories = pmsCategoryMapper.selectPmsCategoryList();
//        List<PmsCategory> firstLevelCategories = new ArrayList<>();
//
//        // 第一级分类
//        for (PmsCategory pmsCategory : pmsCategories) {
//            if (pmsCategory.getParentCid() == 0) {
//                firstLevelCategories.add(pmsCategory);
//            }
//        }
//        // 第二级分类
//        for (PmsCategory firstLevelCategory : firstLevelCategories) {
//            List<PmsCategory> secondLevelCategories = new ArrayList<>();
//            for (PmsCategory pmsCategory : pmsCategories) {
//                if (pmsCategory.getParentCid().equals(firstLevelCategory.getCatId())) {
//                    secondLevelCategories.add(pmsCategory);
//                }
//            }
//            firstLevelCategory.setChildren(secondLevelCategories);
//            // 第三级分类
//            for (PmsCategory secondLevelCategory : secondLevelCategories) {
//                List<PmsCategory> thirdLevelCategories = new ArrayList<>();
//                for (PmsCategory pmsCategory : pmsCategories) {
//                    if (pmsCategory.getParentCid().equals(secondLevelCategory.getCatId())) {
//                        thirdLevelCategories.add(pmsCategory);
//                    }
//                }
//                secondLevelCategory.setChildren(thirdLevelCategories);
//            }
//        }
//        return firstLevelCategories;

    }

    /**
     * 新增商品三级分类
     *
     * @param pmsCategory 商品三级分类
     * @return 结果
     */
    @Override
    public int insertPmsCategory(PmsCategory pmsCategory)
    {
            return pmsCategoryMapper.insertPmsCategory(pmsCategory);
    }

    /**
     * 修改商品三级分类
     *
     * @param pmsCategory 商品三级分类
     * @return 结果
     */
    @Override
    public int updatePmsCategory(PmsCategory pmsCategory)
    {
        return pmsCategoryMapper.updatePmsCategory(pmsCategory);
    }

    /**
     * 批量删除商品三级分类
     *
     * @param catIds 需要删除的商品三级分类主键
     * @return 结果
     */
    @Override
    public int deletePmsCategoryByCatIds(Long[] catIds)
    {
        return pmsCategoryMapper.deletePmsCategoryByCatIds(catIds);
    }

    /**
     * 删除商品三级分类信息
     *
     * @param catId 商品三级分类主键
     * @return 结果
     */
    @Override
    public int deletePmsCategoryByCatId(Long catId)
    {
        return pmsCategoryMapper.deletePmsCategoryByCatId(catId);
    }
}

















